package com.javachmapi.vo;

/**
 * 公共返回
 * create by 宋利军
 */
public class ResponseData<T> {
    /**
     * 表示成功
     */
    public static final byte SUCCESS = 0;
    /**
     * 表示失败
     */
    public static final byte FAILURE = 1;

    private byte state;  //状态,1失败,0成功
    private String msg; //提示消息
    private T data;     //返回数据

    public ResponseData(byte state, String msg, T data) {
        this.state = state;
        this.msg = msg;
        this.data = data;
    }

    public static <T> ResponseData<T> success() {
        return new ResponseData<T>(SUCCESS, "", null);
    }

    public static <T> ResponseData<T> failure() {
        return new ResponseData<T>(FAILURE, "", null);
    }

    public static <T> ResponseData<T> success(String msg) {
        return new ResponseData<T>(SUCCESS, msg, null);
    }

    public static <T> ResponseData<T> failure(String msg) {
        return new ResponseData<T>(FAILURE, msg, null);
    }

    public static <T> ResponseData<T> success(String msg, T data) {
        return new ResponseData<T>(SUCCESS, msg, data);
    }

    public static <T> ResponseData<T> failure(String msg, T data) {
        return new ResponseData<T>(FAILURE, msg, data);
    }

    public ResponseData msg(String msg) {
        this.msg = msg;
        return this;
    }

    public ResponseData data(T data) {
        this.data = data;
        return this;
    }
    public byte getState() {
        return state;
    }

    public void setState(byte state) {
        this.state = state;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

}

